/*
  The <i386_arch.h> header file defines some functions used by the kernel to handle hardware related aspects of the i386 architecture.
*/

#ifndef _I386_ARCH_H
#define _I386_ARCH_H

#include <types.h>
#include <i386_pmode.h>

typedef struct
{
  /* pushed by common handler (PUSHA) */
  dword_t edi, esi, ebp, esp, ebx, edx, ecx, eax;  
  /* pushed by common handler */
  dword_t ds, es, fs, gs;                          
  /* pushed by stub */
  dword_t interrupt_number;                        
  /* pushed by interrupt or stub */
  dword_t error_code;                              
  /* pushed by interrupt */
  dword_t eip, cs, eflags, user_esp, user_ss;      
} uregs_t;


extern void set_data_segments(word_t segment);
extern void halt(void);
extern void reset(void);
extern void clear_registers(void);
extern void issue_iret(void);


extern word_t read_msw(void);   
extern dword_t read_cr0(void);
extern void write_cr0(dword_t value);
extern dword_t read_cr2(void);
extern void write_cr2(dword_t value);
extern dword_t read_cr3(void);
extern void write_cr3(dword_t value);  // PDBR

extern void load_gdt(GDTR_T *gdtr);
extern void load_idt(IDTR_T *idtr);
extern void load_ldt(word_t selector);

extern void load_tr (word_t selector);
extern word_t store_tr(void);

extern void clear_ts(void);    /* clear the task switched flag in cr0 */
extern void clear_df(void);
extern void clear_if(void);
extern void clear_cf(void);

extern void set_df(void);
extern void set_if(void);
extern void set_cf(void);

extern void jump_tss(word_t selector);
extern void call_tss(word_t selector);

extern void invalidate_cache(void);
extern void writeback_invalidate_cache(void);

extern void invalidate_tlb_entry(dword_t address);

extern dword_t read_if(void);

#endif /* _I386_ARCH_H */
